home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 January / macformat46.iso / Shareware Plus / Developers / LogoMation / LogoMation 1.1.3 ƒ / Examples / Lib / general.lib / general.lib
Encoding:
Text File  |  1996-10-25  |  5.9 KB  |  191 lines  |  [UVtx/UVtl]

  1. // general functions for the educational math games
  2. // note: each function saves the drawing environment and restores
  3. //       it before returning
  4.  
  5.  
  6. //////////////////////////////////////////////////////////////////
  7. // function askAt:
  8. // clears a rectangular area, type a prompt and returns the string
  9. //////////////////////////////////////////////////////////////////
  10. Function askAt(x, y, width, prompt)
  11.     Local lastPen, res
  12.     lastPen = penName()           // save the current pen environment
  13.     Pen name="askAtPen"           // use a special pen for this function
  14.     Up
  15.     Goto x, y, 0
  16.     Down
  17.     Fill 1, 65535,65535,65535     // erase width x 20 rectangle
  18.         Repeat 2
  19.             Forward width
  20.             Left 90
  21.             Forward 20
  22.             Left 90
  23.     Up
  24.     Goto x+10, y+5, 0
  25.     Print prompt,move              // print the prompt
  26.     res = ask(width - (x()-x+10))  // read the string from the user   
  27.     Pen name=lastPen               // restore the original environment
  28.     Return res                     // return the string
  29.  
  30.  
  31. //////////////////////////////////////////////////////////////////////////////
  32. // function printOver -- like print, but erases its print area before printing
  33. //////////////////////////////////////////////////////////////////////////////
  34. Function printOver(str)
  35.     Local lastRGB, lastY, lastDir, width, height
  36.     lastDir = dir()
  37.     width = sWidth(str)
  38.     lastY = y()
  39.     lastRGB = rgb()
  40.     Goto x(),y()-sDescent(),0
  41.     Color random(65000),
  42.     Fill 1, bg_rgb()
  43.         Repeat 2
  44.             Forward width
  45.             Left 90
  46.             Forward sAscent()+sDescent()
  47.             Left 90
  48.     Goto x(), lastY, lastDir
  49.     Print str
  50.     Color lastRGB
  51.  
  52.  
  53. ///////////////////////////////////////////////////////////
  54. // circle  -- draw a circle around the current point
  55. // circleS -- like circle, but save/restore the drawing env
  56. ///////////////////////////////////////////////////////////
  57. Function circle(radius, fillRGB, penRGB, penWidth)
  58.     Up
  59.     Goto 0,-radius,0
  60.     Down
  61.     Width penWidth
  62.     Color penRGB
  63.     Fill 1,fillRGB
  64.         Circle radius
  65.         Forward 2*π*radius
  66. Function circleS(radius, fillRGB, penRGB, penWidth,                lastPen)
  67.     lastPen = penName()                   // save the current pen environment
  68.     Pen name="circlePen", copy=lastPen    // use a special pen for this function
  69.     circle(radius, fillRGB, penRGB, penWidth) 
  70.     Pen name=lastPen                      // restore the original environment
  71.  
  72.  
  73. ////////////////////////////////////////////////////////////////////////////////
  74. // prFraction - print a fraction at an X,Y location, return the printed width //
  75. ////////////////////////////////////////////////////////////////////////////////
  76. Function prFraction(x, y, nom, denom)
  77.     Local lastPen, bar, s1, s2
  78.     lastPen = penName()                     // save the current pen environment
  79.     Pen name="prFractionPen", copy=lastPen  // use a special pen for this function
  80.     s1 = " " . nom . " "
  81.     s2 = " " . denom . " "
  82.     bar = sWidth(s1)
  83.     If sWidth(s2) > bar
  84.         bar = sWidth(s2)
  85.     Up                       // draw the bar
  86.     Goto x, y, 0
  87.     Down
  88.     Forward bar
  89.     Up                       // the nom
  90.     Goto x+(bar-sWidth(s1))/2, y+3, dir()
  91.     Print s1
  92.     Goto x+(bar-sWidth(s2))/2, y-(sAscent()+sDescent()), 0
  93.     Print s2
  94.     Pen name=lastPen               // restore the original environment
  95.     Return bar
  96.     
  97.     
  98. ///////////////////////
  99. // pie -- draw a pie //
  100. ///////////////////////
  101. Function pie(x, y, start, delta, radius, patt, color)
  102.     Local lastPen
  103.     lastPen = penName()
  104.     Pen name="animateFractionPen", copy=lastPen
  105.     Goto x, y,start
  106.     Fill patt, color
  107.         Down
  108.         Straight
  109.         Forward radius
  110.         Right 90
  111.         Circle -radius
  112.         Forward radius*2*π*delta/360
  113.         Goto x,y,0
  114.     Pen name=lastPen 
  115.  
  116.  
  117.  
  118. ///////////////////////////////////////////
  119. // Intro -- print an introductory screen //
  120. ///////////////////////////////////////////
  121. Function Intro(line, snd1, snd2)
  122.     Local c,p,x,x1,y,a,i,r,lastPen
  123.     lastPen = penName()
  124.     
  125.     // define 10 erasers -- will be cached for the next run
  126.     randomize()
  127.     Repeat i,1,10
  128.         Picture "Intro P" . i
  129.             Fill 1, 65000-random(32000),32000+random(32000),random(65000)
  130.                 Left 5-random(10)
  131.                 Repeat 4
  132.                     Forward 15
  133.                     Left 90
  134.  
  135.     // clear the screen, set a light random background
  136.     Clear 40000+random(25000), 40000+random(25000), 40000+random(25000)
  137.     
  138.     // select the location for the text, init the eraser pens
  139.     Pen name="Intro TE", fontname="Times",fontstyle="Bold",fontsize=20
  140.     x = -width()/2 + (width()-sWidth(line))/2 // center the line
  141.     y = height()/4                             // 3/4 of the way
  142.     p = "Intro P" . int(1.5+random(9))         // selected eraser's picture
  143.     Pen name="Intro PE", picture=p, speed=300  // the animated eraser pen
  144.     Up
  145.     Goto x-50, y-8,45
  146.     Down
  147.     Pen name="Intro PW"                        // the actual white pen
  148.     Up
  149.     Goto x-50, y-8,45
  150.     Down
  151.     Color 65500,65500,65500                       // white eraser trail
  152.     Width 10
  153.     
  154.     // the eraser op
  155.     Repeat
  156.         x1 = x()
  157.         r = random(3)
  158.         Sound snd1,nowait
  159.         Repeat 5
  160.             Pen name="Intro PE"
  161.             Forward 9+r
  162.             Pen name="Intro PW"
  163.             Forward 9+r
  164.         Pen name="Intro PE"
  165.         r = random(10)
  166.         Goto x1+15, y-r,45
  167.         Pen name="Intro PW"
  168.         Goto x1+15, y-r,45
  169.         If x() > (x + sWidth(line) + 80)
  170.             Pen name="Intro PE", end="no"
  171.             Forward 1
  172.             Break
  173.        Sound "",wait
  174.  
  175.  
  176.     // print the text, one char at a time
  177.     Pen name="Intro TE"
  178.     Color 5005,16937,52735
  179.     Up
  180.     Goto x,y,0
  181.     Repeat i,1,length(line)
  182.         c = substr(line,i-1,1)
  183.         Print c, move
  184.         If c ≠ " "
  185.             Sound snd2,wait
  186.         Else
  187.             Pause random(0.4)+0.2
  188.  
  189.     // restore env, return
  190.     Pen name=lastPen 
  191.